package com.bjc.nio;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

/**
 * @program: nettypro
 * @description: 使用transferForm完成拷贝
 * @author: bjc
 * @create: 2021-09-03 21:32
 */
public class NIOFileChannel04 {

    public static void main(String[] args) throws Exception{
        //创建相关流
        FileInputStream fileInputStream = new FileInputStream("D:\\iotest_delete\\happyadream.jpg");
        FileOutputStream fileOutputStream = new FileOutputStream("D:\\iotest_delete\\happyadream2.jpg");

        //获取各个流对应的filechannel
        FileChannel source = fileInputStream.getChannel();
        FileChannel destch = fileOutputStream.getChannel();

        //使用transferForm完成拷贝
        destch.transferFrom(source,0,source.size());
        //关闭相关通道和流
        source.close();
        destch.close();
        fileInputStream.close();
        fileOutputStream.close();
    }
}
